home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Rice_CMS / gopher24 / gopherdi.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1993-01-18  |  8.4 KB  |  325 lines

  1. /*
  2.  *        Name: GOPHERDH REXX (GOPHERDI)
  3.  *              pipeline stage for interpreting the CMS HELP database
  4.  *      Author: Rick Troth, Rice University, Information Systems
  5.  *        Date: 1992-Apr-25, Jun-24, Jul-29, 1993-Jan-18
  6.  *
  7.  *              This gem is supplied with the Rice CMS Gopher server.
  8.  *              Feel free to use it as an example of building
  9.  *              your own Gopher server smart pipeline stages.
  10.  */
  11.  
  12. Parse Source . . . . . arg0 .
  13. argo = arg0 || ':'
  14. Parse Arg args
  15. Say argo args
  16.  
  17. /*  accept a command line;  remember options  */
  18. Parse Upper Arg item '(' opts ')' .
  19.  
  20. /*  the "item" may have leading "path" parts,  which we just ignore   */
  21. Do While Index(item,'/') > 0; Parse Var item . '/' item; End
  22.  
  23. /*  make it right  */
  24. If Words(item) = 0 Then item = "TASK HELP"
  25. If Words(item) = 1 Then topic = "CMS"
  26.                    Else Parse Var item topic item .
  27.  
  28. /*  is it a task? menu? or leaf item?  */
  29. If item = "TASK" Then Do; item = topic; topic = "TASK"; End
  30. If item = "MENU" Then Do; item = topic; topic = "MENU"; End
  31.  
  32. /*  call the right pipeline stages  */
  33. Select  /*  topic  */
  34.  
  35.     When topic = "TASKTEXT" Then Call HELPTEXT
  36.     When topic = "MENUTEXT" Then Call HELPTEXT
  37.  
  38.     When topic = "TASK"     Then Call HELPTASK
  39.  
  40.     When topic = "MENU"     Then CALL HELPMENU
  41.  
  42.     Otherwise                    CALL HELPITEM
  43.  
  44.     End  /*  Select  topic  */
  45.  
  46. Exit rc
  47.  
  48.  
  49.  
  50. /* ------------------------------------------------------------ HELPITEM
  51.  *  Neither a TASK nor a MENU node;  this is a leaf.
  52.  */
  53. HELPITEM:
  54.  
  55. 'CALLPIPE COMMAND HELP' topic item '(NOSCREEN' opts '| *:'
  56.  
  57. Return
  58.  
  59.  
  60.  
  61. /* ------------------------------------------------------------ HELPTEXT
  62.  *  This section is a left-over from the pre-Panda version.
  63.  *  It is still called if you invoke the older HELPTASK or HELPMENU.
  64.  */
  65. HELPTEXT:
  66.  
  67. /*  it would be way-cool if we could present the preliminary text     *
  68.  *  ("user instructions",  or whatever you want to call it)           *
  69.  *  as a plain-text item from the menu we're creating here.           */
  70.  
  71. If topic = "MENUTEXT" Then 'ADDPIPE <' item 'HELPMENU * | *.INPUT:'
  72.                       Else 'ADDPIPE <' item 'HELPTASK * | *.INPUT:'
  73. If rc ^= 0 Then Return
  74.  
  75. /* read and replay displayed text or "user instructions" from task */
  76. Do Forever
  77.  
  78.     'PEEKTO LINE'
  79.     If rc ^= 0 Then Leave
  80.  
  81.     If Strip(line) = "" & Strip(prev) = "" Then Leave
  82.  
  83.     If Left(line,1) ^= '.' Then Do
  84.         /* remove any HELP control sequences */
  85.         p = Index(line,'4A'x)
  86.         Do While p > 0
  87.             line = Left(line,p-1) || Substr(line,p+2)
  88.             p = Index(line,'4A'x)
  89.             End
  90.         /* and send this line of text down the pipe */
  91.         'OUTPUT' line
  92.         If rc ^= 0 Then Leave
  93.         End
  94.  
  95.     prev = line
  96.     'READTO'
  97.     If rc ^= 0 Then Leave
  98.  
  99.     End  /*  Do  Forever  */
  100.  
  101. Return
  102.  
  103.  
  104.  
  105. /* ------------------------------------------------------------ HELPTASK
  106.  *  Selected item is a TASK.   Presume we have GOPSRVMB following.
  107.  */
  108. HELPTASK:
  109.  
  110. 'ADDPIPE <' item 'HELPTASK * | *.INPUT:'
  111. If rc ^= 0 Then Return
  112.  
  113. /* first show the displayed text or user instructions as "info" */
  114. Do Forever
  115.  
  116.     'PEEKTO LINE'
  117.     If rc ^= 0 Then Leave
  118.  
  119.     If Strip(line) = "" & Strip(prev) = "" Then Leave
  120.     If Left(line,1) ^= '.' Then 'OUTPUT' 'i' || line
  121.     If rc ^= 0 Then Leave
  122.     prev = line
  123.  
  124.     'READTO'
  125.     If rc ^= 0 Then Leave
  126.  
  127.     End  /*  Do  Forever  */
  128.  
  129. /* now interpret the task lines and make a menu */
  130. Do Forever
  131.  
  132.     'PEEKTO LINE'
  133.     If rc ^= 0 Then Leave
  134.  
  135.     If Left(line,1) ^= '.' & Strip(line) ^= "" Then Do
  136.         /* ignoring blank lines and control lines */
  137.         Parse Var line 1 path 25 title
  138.  
  139.         /* remove HELP control sequences from titles */
  140.         p = Index(title,'4A'x)
  141.         Do While p > 0
  142.             title = Left(title,p-1) || Substr(title,p+2)
  143.             p = Index(title,'4A'x)
  144.             End
  145.  
  146.         type = "0"
  147.         Parse Upper Var path topic item . '(' . ')' .
  148.         If item = "TASK" Then Do; item = topic; topic = "TASK"; End
  149.         If item = "MENU" Then Do; item = topic; topic = "MENU"; End
  150.         If topic = "TASK" | topic = "MENU" Then type = "1"
  151.         'OUTPUT' type || title || '05'x || type || topic item
  152. /*      'OUTPUT' type || title || '05'x || type || path               */
  153.         If rc ^= 0 Then Leave
  154.         End  /*  If  ..  Do  */
  155.  
  156.     'READTO'
  157.     If rc ^= 0 Then Leave
  158.  
  159.     End  /*  Do  Forever  */
  160.  
  161. Return
  162.  
  163.  
  164.  
  165. /* ------------------------------------------------------------ HELPMENU
  166.  *  Selected item is a MENU.   Presume we have GOPSRVMB follows.
  167.  */
  168. HELPMENU:
  169.  
  170. 'ADDPIPE <' item 'HELPMENU * | *.INPUT:'
  171. If rc ^= 0 Then Return
  172.  
  173. topic = item
  174.  
  175. /* first show the displayed text or user instructions as "info" */
  176. Do Forever
  177.  
  178.     'PEEKTO LINE'
  179.     If rc ^= 0 Then Leave
  180.  
  181.     /* Menu type */
  182.     if left(line,3) = '.mt' then parse var line . topic .
  183.  
  184.     If Strip(line) = "" & Strip(prev) = "" Then Leave
  185.     If Left(line,1) ^= '.' Then 'OUTPUT' 'i' || line
  186.     If rc ^= 0 Then Leave
  187.     prev = line
  188.  
  189.     'READTO'
  190.     If rc ^= 0 Then Leave
  191.  
  192.     End  /*  Do  While  */
  193.  
  194. Do Forever
  195.  
  196.     'PEEKTO LINE'
  197.     If rc ^= 0 Then Leave
  198.  
  199.     /* Menu type */
  200.     if left(line,3) = '.mt' then parse var line . topic .
  201.  
  202.     If Left(line,1) ^= '.' & Strip(line) ^= "" Then Do
  203.         Parse Var line item .
  204.         key = Left(item,1)
  205.         Select  /*  key  */
  206.             When key = '*' Then
  207.                 'OUTPUT' "1" || line || '05'x ||  ,
  208.                     "1" || "MENU" Substr(item,2)
  209.             When key = ':' Then
  210.                 'OUTPUT' "1" || line || '05'x || ,
  211.                     "1" || "TASK" Substr(item,2)
  212.             Otherwise
  213.                 'OUTPUT' "0" || line || '05'x || ,
  214.                     "0" || topic item
  215.             End  /*  Select  key  */
  216.         If rc ^= 0 Then Leave
  217.         End  /*  If  ..  Do  */
  218.  
  219.     'READTO'
  220.     If rc ^= 0 Then Leave
  221.  
  222.     End  /*  Do  While  */
  223.  
  224. Return
  225.  
  226.  
  227.  
  228. /*  The following two routines are useful if you serve    *
  229.  *  clients that can't handle the Panda "info" type       */
  230.  
  231.  
  232.  
  233. /* ------------------------------------------------------------ HELPTASK
  234.  */
  235. HELPTASK:
  236.  
  237. 'ADDPIPE DISK' item 'HELPTASK * | *.INPUT:'
  238.  
  239. /* first consume the displayed text or "user instructions" */
  240. 'PEEKTO LINE'
  241. Do While rc = 0
  242.     If Strip(line) = "" & Strip(prev) = "" Then Leave
  243.     prev = line
  244.     'READTO'
  245.     'PEEKTO LINE'
  246.     End  /*  Do  While  */
  247.  
  248. 'OUTPUT' "0" || item "task heading text" || '05'x || ,
  249.          "0" || "TASKTEXT" item
  250.  
  251. /* now interpret the task lines and make a menu */
  252. 'PEEKTO LINE'
  253. Do While rc = 0
  254.     If Left(line,1) ^= '.' & Strip(line) ^= "" Then Do
  255.         /* ignoring blank lines and control lines */
  256.         Parse Var line 1 path 25 title
  257.  
  258.         /* remove HELP control sequences from titles */
  259.         p = Index(title,'4A'x)
  260.         Do While p > 0
  261.             title = Left(title,p-1) || Substr(title,p+2)
  262.             p = Index(title,'4A'x)
  263.             End
  264.  
  265.         type = "0"
  266.         Parse Upper Var path topic item .
  267.         If item = "TASK" Then Do; item = topic; topic = "TASK"; End
  268.         If item = "MENU" Then Do; item = topic; topic = "MENU"; End
  269.         If topic = "TASK" | topic = "MENU" Then type = "1"
  270.         'OUTPUT' type || title || '05'x || type || topic item
  271. /*      'OUTPUT' type || title || '05'x || type || path               */
  272.         End  /*  If  ..  Do  */
  273.  
  274.     'READTO'
  275.     'PEEKTO LINE'
  276.     End  /*  Do  While  */
  277.  
  278. Return
  279.  
  280.  
  281.  
  282. /* ------------------------------------------------------------ HELPMENU
  283.  */
  284. HELPMENU:
  285.  
  286. 'ADDPIPE DISK' item 'HELPMENU * | *.INPUT:'
  287.  
  288. topic = item
  289.  
  290. /* first consume the displayed text or "user instructions" */
  291. 'PEEKTO LINE'
  292. Do While rc = 0
  293.     If Strip(line) = "" & Strip(prev) = "" Then Leave
  294.     prev = line
  295.     'READTO'
  296.     'PEEKTO LINE'
  297.     End  /*  Do  While  */
  298.  
  299. 'OUTPUT' "0" || item "menu heading text" || '05'x || ,
  300.          "0" || "MENUTEXT" item
  301.  
  302. 'PEEKTO LINE'
  303. Do While rc = 0
  304.     If Left(line,1) ^= '.' & Strip(line) ^= "" Then Do
  305.         Parse Var line item .
  306.         key = Left(item,1)
  307.         Select  /*  key  */
  308.             When key = '*' Then
  309.                 'OUTPUT' "1" || line || '05'x ||  ,
  310.                     "1" || "MENU" Substr(item,2)
  311.             When key = ':' Then
  312.                 'OUTPUT' "1" || line || '05'x || ,
  313.                     "1" || "TASK" Substr(item,2)
  314.             Otherwise
  315.                 'OUTPUT' "0" || line || '05'x || ,
  316.                     "0" || topic item
  317.             End  /*  Select  key  */
  318.         End  /*  If  ..  Do  */
  319.     'READTO'
  320.     'PEEKTO LINE'
  321.     End  /*  Do  While  */
  322.  
  323. Return
  324.  
  325.